class Solution {
public:
    vector<vector<int> > edges;
    vector<int> visited;
    bool isvalid = true;
    
    bool dfs(int start,int end){
        if(start == end){
            return true;
        }
        if(visited[start] != 0){
            return false;
        }
        visited[start] = 1;
        for(auto& node : edges[start]){
            if(!visited[node]){
                if(dfs(node,end)){
                    return true;
                }
            }
        }
        return false;
    }
    
    bool findWhetherExistsPath(int n, vector<vector<int>>& graph, int start, int target) {
        edges.resize(n);
        visited.resize(n);
        for(auto& vc : graph){
            edges[vc[0]].push_back(vc[1]);
        }
        bool ret = dfs(start,target);
        return ret;
    }
};
